export function useTable() {
    // 机构树：一层 => 树结构
    const arrayToTree = (items, parentIdKey = 'parentId', idKey = 'id') => {
        const tree: Array<any> = []
        const childrenOf = {}
        items.forEach((item) => {
            const parentId = item[parentIdKey]
            if (parentId === 0) {
                tree.push(item)
            }
            else {
                if (!childrenOf[parentId]) {
                    childrenOf[parentId] = []
                }
                childrenOf[parentId].push(item)
            }
        })
        function findChildren(items) {
            return items.map((item) => {
                const foundChildren = childrenOf[item[idKey]] || []
                item.children = findChildren(foundChildren)
                item.disabled = item.status === '1'
                return item
            })
        }
        return findChildren(tree)
    }
    return { arrayToTree }
}
